<?php
/**
 * This class can be added to a form, it represents the HTML tag "fieldset". Child elements can be
 * added to this class.
 * 
 * @author Niels Janssen
 * @since 2008-07-08
 * @package Form.Containers
 *
 */
class FieldSet extends FormContainer {
	
	/**
	 * The name that will be displayed in the legend of this fieldset.
	 *
	 * @var String
	 */
	protected $name = '';

	/**
	 * Constructor for FieldSet, initializes some variables.
	 *
	 * @param String $name
	 * @param Array $properties
	 */
	function __construct( $name, array $properties = array() ) {
		parent::__construct ( $name, $properties );
	}

	/**
	 * Sets the name for the fieldset.
	 *
	 * @param String $name
	 */
	public function setName( $name ) {
		$this->name = $name;
	}

	/**
	 * @return String 
	 * @see FormNode::__toString() 
	 */
	public function __toString( ) {
		$fieldset = '<fieldset class="'.( $this->getProperty("class") != '' ? $this->getProperty("class") : 'fieldset' ).'"'.( $this->getProperty('id') != '' ? ' id="' . $this->getProperty('id') . '"' : '' ).'><legend>' . $this->name . '</legend>';
		
		foreach( $this->children as $child ) {
			$fieldset .= $child;
		}
		
		$fieldset .= '</fieldset>';
		
		return $fieldset;
	}
}

?>